package com.bree.erp.entity;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQuery;
import javax.persistence.OneToOne;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

@NamedQuery(name=InventoryFlow.QUERY_SELECT_ALL_INVENTORYFLOW,
query = "SELECT if FROM InventoryFlow if")
@Entity
public class InventoryFlow implements CrudId<Long>{

	private static final long serialVersionUID = 1L;

	public static final String QUERY_SELECT_ALL_INVENTORYFLOW = "selectAllInventoryFlow";

	public static final int COL_LOCATIONBIN_LEN = 15;
	public static final int COL_REFERENCE_LEN = 20;
	
	@Id
	@GeneratedValue(strategy=GenerationType.SEQUENCE)
	private Long id;
	
	@OneToOne
	private Warehouse warehouse;
	
	@Column(length=COL_LOCATIONBIN_LEN)
	private String locationBin;

	@OneToOne
	private PartUnit partUnit;
	
	private double quantity;
	
	@Enumerated(EnumType.STRING)
	private InventoryStatus status;
	
	@ManyToOne
	private PurchaseOrder purchaseOrder;

	@Column(length=COL_REFERENCE_LEN)
	private String reference;
	
	@OneToOne
	private User loggedBy;

	@Temporal(TemporalType.TIMESTAMP)
	private Date loggedDate;
	
	@Override
	public Long getId() {
		return id;
	}
	
	public String getWarehouseName() {
		if(this.warehouse != null) {
			return warehouse.getName();
		}
		
		return "";
	}
	
	public String getShortName() {
		return partUnit == null ? "" : partUnit.getShortName();
	}
	
	public String getShortUnit() {
		return partUnit == null ? "" : partUnit.getShortUnit();
	}
	
	public String getShortBrand() {
		return partUnit == null ? "" : partUnit.getShortBrand();
	}

	public String getPart() {
		return partUnit == null ? "" : partUnit.getPart();
	}
	
	public String getPoNumStr() {
		return this.purchaseOrder == null || this.purchaseOrder.getPoNumber() == null ? "" : this.purchaseOrder.getPoNumber().toString();
	}
	

	/**
	 * @return the warehouse
	 */
	public Warehouse getWarehouse() {
		return warehouse;
	}

	/**
	 * @param warehouse the warehouse to set
	 */
	public void setWarehouse(Warehouse warehouse) {
		this.warehouse = warehouse;
	}

	/**
	 * @return the locationBin
	 */
	public String getLocationBin() {
		return locationBin == null ? "" : locationBin;
	}

	/**
	 * @param locationBin the locationBin to set
	 */
	public void setLocationBin(String locationBin) {
		this.locationBin = locationBin;
	}

	/**
	 * @return the partUnit
	 */
	public PartUnit getPartUnit() {
		return partUnit;
	}

	/**
	 * @param partUnit the partUnit to set
	 */
	public void setPartUnit(PartUnit partUnit) {
		this.partUnit = partUnit;
	}

	/**
	 * @return the quantity
	 */
	public double getQuantity() {
		return quantity;
	}

	/**
	 * @param quantity the quantity to set
	 */
	public void setQuantity(double quantity) {
		this.quantity = quantity;
	}

	/**
	 * @return the status
	 */
	public InventoryStatus getStatus() {
		return status;
	}

	/**
	 * @param status the status to set
	 */
	public void setStatus(InventoryStatus status) {
		this.status = status;
	}

	/**
	 * @return the loggedBy
	 */
	public User getLoggedBy() {
		return loggedBy;
	}

	/**
	 * @param loggedBy the loggedBy to set
	 */
	public void setLoggedBy(User loggedBy) {
		this.loggedBy = loggedBy;
	}

	/**
	 * @return the loggedDate
	 */
	public Date getLoggedDate() {
		return loggedDate;
	}

	/**
	 * @param loggedDate the loggedDate to set
	 */
	public void setLoggedDate(Date loggedDate) {
		this.loggedDate = loggedDate;
	}

	/**
	 * @param id the id to set
	 */
	public void setId(Long id) {
		this.id = id;
	}

	/**
	 * @return the reference
	 */
	public String getReference() {
		return reference;
	}

	/**
	 * @param reference the reference to set
	 */
	public void setReference(String reference) {
		this.reference = reference;
	}

	/**
	 * @return the purchaseOrder
	 */
	public PurchaseOrder getPurchaseOrder() {
		return purchaseOrder;
	}

	/**
	 * @param purchaseOrder the purchaseOrder to set
	 */
	public void setPurchaseOrder(PurchaseOrder purchaseOrder) {
		this.purchaseOrder = purchaseOrder;
	}

}
